﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace LostLib
{
	/// <summary>
	/// Some extensions for IEnumerator interface
	/// </summary>
	public static class IEnumeratorExtensions
	{
		/// <summary>
		/// Returns next element in sequence, advancing position by 1.
		/// </summary>
		/// <param name="enumerator">Sequence enumerator.</param>
		/// <returns>Next element.</returns>
		/// <exception cref="InvalidOperationException">Thrown if enumerator is positioned behind the sequence.</exception>
		public static object GetNext(this IEnumerator enumerator)
		{
			if (!enumerator.MoveNext()) throw new InvalidOperationException();
			return enumerator.Current;
		}
		/// <summary>
		/// Returns next element in sequence, advancing position by 1.
		/// </summary>
		/// <param name="enumerator">Sequence enumerator.</param>
		/// <returns>Next element.</returns>
		/// <exception cref="InvalidOperationException">Thrown if enumerator is positioned behind the sequence.</exception>
		public static T GetNext<T>(this IEnumerator<T> enumerator)
		{
			if (!enumerator.MoveNext()) throw new InvalidOperationException();
			return enumerator.Current;
		}
	}
}
